package com.tom.demo.controller.approvalsettings;

import com.tom.demo.common.annotation.OperaLog;
import com.tom.demo.common.entity.OaProcessTemplate;
import com.tom.demo.common.enumeration.OperaTypeEnum;
import com.tom.demo.common.response.Result;
import com.tom.demo.service.approvalsettings.OaProcessTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = {"审批模板"})
@RestController
@RequestMapping("/oaProcessTemplate")
public class OaProcessTemplateController {

    @Resource
    private OaProcessTemplateService oaProcessTemplateService;

    @PostMapping(path = {"/list"})
    @ApiOperation(value = "获取分页审批模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", defaultValue = "1", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页查询多少条", defaultValue = "10", dataType = "int", paramType = "query")
    })
    public Result list(@RequestParam(value = "page",defaultValue = "1")Integer page,
                        @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                        @RequestBody OaProcessTemplate oaProcessTemplate){
        return oaProcessTemplateService.list(page,pageSize,oaProcessTemplate);
    }


    @PostMapping(path = {"/save"})
    @ApiOperation(value = "保存审批模板")
    @OperaLog(operaModel = "审批模板",operaType = OperaTypeEnum.ADD,operaDesc = "保存审批模板")
    public Result save(@RequestBody OaProcessTemplate oaProcessTemplate){
        return oaProcessTemplateService.save(oaProcessTemplate);
    }

    @DeleteMapping(path = {"/deleteById/{id}"})
    @ApiOperation(value = "删除审批模板")
    @OperaLog(operaModel = "审批模板",operaType = OperaTypeEnum.DELETE,operaDesc = "删除审批模板")
    public Result deleteById(@PathVariable(value = "id")String id){
        return oaProcessTemplateService.deleteById(id);
    }

    @GetMapping(path = {"/deploymentProcess"})
    @ApiOperation(value = "部署流程")
    @OperaLog(operaModel = "审批模板",operaType = OperaTypeEnum.ADD,operaDesc = "部署流程")
    public Result deploymentProcess(@RequestParam(value = "id")String id){
        return oaProcessTemplateService.deploymentProcess(id);
    }

    @GetMapping(path = {"/processDefinitionKey"})
    @ApiOperation(value = "根据流程定义key获取表单信息")
    public Result processDefinitionKey(@RequestParam(value = "processDefinitionKey")String processDefinitionKey){
        return oaProcessTemplateService.processDefinitionKey(processDefinitionKey);
    }
}
